package mac.eventRecognizer.pedlParser;

/** This class contains 6 relational operators- >,>=,<,<=,== and != - on 5 types: 
 * Integer, Long, Float, Double and Char.  These operators are used for
 * evaluating ASTCondition node.
 *
 * @version 0.1
 * @author Moonjoo Kim
 */
class ASTConditionAux {
 /* Integer vs other type */
 static boolean evalRelAux(Integer lv, Integer rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.intValue() > rv.intValue(); break;
	 case ASTCondition.GE : result = lv.intValue() >= rv.intValue(); break;
	 case ASTCondition.LT : result = lv.intValue() < rv.intValue(); break;
	 case ASTCondition.LE : result = lv.intValue() <= rv.intValue(); break;
	 case ASTCondition.EQ : result = lv.intValue() == rv.intValue(); break;
	 case ASTCondition.NEQ : result = lv.intValue() != rv.intValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Integer lv, Long rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.intValue() > rv.longValue(); break;
	 case ASTCondition.GE : result = lv.intValue() >= rv.longValue();break;
	 case ASTCondition.LT : result = lv.intValue() < rv.longValue(); break;
	 case ASTCondition.LE : result = lv.intValue() <= rv.longValue();break;
	 case ASTCondition.EQ : result = lv.intValue() == rv.longValue();break;
	 case ASTCondition.NEQ: result = lv.intValue() != rv.longValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Integer lv, Float rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.intValue() > rv.floatValue(); break;
	 case ASTCondition.GE : result = lv.intValue() >= rv.floatValue();break;
	 case ASTCondition.LT : result = lv.intValue() < rv.floatValue(); break;
	 case ASTCondition.LE : result = lv.intValue() <= rv.floatValue();break;
	 case ASTCondition.EQ : result = lv.intValue() == rv.floatValue();break;
	 case ASTCondition.NEQ: result = lv.intValue() != rv.floatValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Integer lv, Double rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.intValue() > rv.doubleValue(); break;
	 case ASTCondition.GE : result = lv.intValue() >= rv.doubleValue();break;
	 case ASTCondition.LT : result = lv.intValue() < rv.doubleValue(); break;
	 case ASTCondition.LE : result = lv.intValue() <= rv.doubleValue();break;
	 case ASTCondition.EQ : result = lv.intValue() == rv.doubleValue();break;
	 case ASTCondition.NEQ: result = lv.intValue() != rv.doubleValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Integer lv, Character rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.intValue() > rv.charValue(); break;
	 case ASTCondition.GE : result = lv.intValue() >= rv.charValue();break;
	 case ASTCondition.LT : result = lv.intValue() < rv.charValue(); break;
	 case ASTCondition.LE : result = lv.intValue() <= rv.charValue();break;
	 case ASTCondition.EQ : result = lv.intValue() == rv.charValue();break;
	 case ASTCondition.NEQ: result = lv.intValue() != rv.charValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }

 /* Long vs other type */
static boolean evalRelAux(Long lv, Integer rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.longValue() > rv.intValue(); break;
	 case ASTCondition.GE : result = lv.longValue() >= rv.intValue(); break;
	 case ASTCondition.LT : result = lv.longValue() < rv.intValue(); break;
	 case ASTCondition.LE : result = lv.longValue() <= rv.intValue(); break;
	 case ASTCondition.EQ : result = lv.longValue() == rv.intValue(); break;
	 case ASTCondition.NEQ : result = lv.longValue() != rv.intValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Long lv, Long rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.longValue() > rv.longValue(); break;
	 case ASTCondition.GE : result = lv.longValue() >= rv.longValue();break;
	 case ASTCondition.LT : result = lv.longValue() < rv.longValue(); break;
	 case ASTCondition.LE : result = lv.longValue() <= rv.longValue();break;
	 case ASTCondition.EQ : result = lv.longValue() == rv.longValue();break;
	 case ASTCondition.NEQ: result = lv.longValue() != rv.longValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Long lv, Float rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.longValue() > rv.floatValue(); break;
	 case ASTCondition.GE : result = lv.longValue() >= rv.floatValue();break;
	 case ASTCondition.LT : result = lv.longValue() < rv.floatValue(); break;
	 case ASTCondition.LE : result = lv.longValue() <= rv.floatValue();break;
	 case ASTCondition.EQ : result = lv.longValue() == rv.floatValue();break;
	 case ASTCondition.NEQ: result = lv.longValue() != rv.floatValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Long lv, Double rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.longValue() > rv.doubleValue(); break;
	 case ASTCondition.GE : result = lv.longValue() >= rv.doubleValue();break;
	 case ASTCondition.LT : result = lv.longValue() < rv.doubleValue(); break;
	 case ASTCondition.LE : result = lv.longValue() <= rv.doubleValue();break;
	 case ASTCondition.EQ : result = lv.longValue() == rv.doubleValue();break;
	 case ASTCondition.NEQ: result = lv.longValue() != rv.doubleValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Long lv, Character rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.longValue() > rv.charValue(); break;
	 case ASTCondition.GE : result = lv.longValue() >= rv.charValue();break;
	 case ASTCondition.LT : result = lv.longValue() < rv.charValue(); break;
	 case ASTCondition.LE : result = lv.longValue() <= rv.charValue();break;
	 case ASTCondition.EQ : result = lv.longValue() == rv.charValue();break;
	 case ASTCondition.NEQ: result = lv.longValue() != rv.charValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 /* Float vs other type */
static boolean evalRelAux(Float lv, Integer rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.floatValue() > rv.intValue(); break;
	 case ASTCondition.GE : result = lv.floatValue() >= rv.intValue(); break;
	 case ASTCondition.LT : result = lv.floatValue() < rv.intValue(); break;
	 case ASTCondition.LE : result = lv.floatValue() <= rv.intValue(); break;
	 case ASTCondition.EQ : result = lv.floatValue() == rv.intValue(); break;
	 case ASTCondition.NEQ : result = lv.floatValue() != rv.intValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Float lv, Long rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.floatValue() > rv.longValue(); break;
	 case ASTCondition.GE : result = lv.floatValue() >= rv.longValue();break;
	 case ASTCondition.LT : result = lv.floatValue() < rv.longValue(); break;
	 case ASTCondition.LE : result = lv.floatValue() <= rv.longValue();break;
	 case ASTCondition.EQ : result = lv.floatValue() == rv.longValue();break;
	 case ASTCondition.NEQ: result = lv.floatValue() != rv.longValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Float lv, Float rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.floatValue() > rv.floatValue(); break;
	 case ASTCondition.GE : result = lv.floatValue() >= rv.floatValue();break;
	 case ASTCondition.LT : result = lv.floatValue() < rv.floatValue(); break;
	 case ASTCondition.LE : result = lv.floatValue() <= rv.floatValue();break;
	 case ASTCondition.EQ : result = lv.floatValue() == rv.floatValue();break;
	 case ASTCondition.NEQ: result = lv.floatValue() != rv.floatValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Float lv, Double rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.floatValue() > rv.doubleValue(); break;
	 case ASTCondition.GE : result = lv.floatValue() >= rv.doubleValue();break;
	 case ASTCondition.LT : result = lv.floatValue() < rv.doubleValue(); break;
	 case ASTCondition.LE : result = lv.floatValue() <= rv.doubleValue();break;
	 case ASTCondition.EQ : result = lv.floatValue() == rv.doubleValue();break;
	 case ASTCondition.NEQ: result = lv.floatValue() != rv.doubleValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Float lv, Character rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.floatValue() > rv.charValue(); break;
	 case ASTCondition.GE : result = lv.floatValue() >= rv.charValue();break;
	 case ASTCondition.LT : result = lv.floatValue() < rv.charValue(); break;
	 case ASTCondition.LE : result = lv.floatValue() <= rv.charValue();break;
	 case ASTCondition.EQ : result = lv.floatValue() == rv.charValue();break;
	 case ASTCondition.NEQ: result = lv.floatValue() != rv.charValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 /* Double vs other type */
static boolean evalRelAux(Double lv, Integer rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.doubleValue() > rv.intValue(); break;
	 case ASTCondition.GE : result = lv.doubleValue() >= rv.intValue(); break;
	 case ASTCondition.LT : result = lv.doubleValue() < rv.intValue(); break;
	 case ASTCondition.LE : result = lv.doubleValue() <= rv.intValue(); break;
	 case ASTCondition.EQ : result = lv.doubleValue() == rv.intValue(); break;
	 case ASTCondition.NEQ : result = lv.doubleValue() != rv.intValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Double lv, Long rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.doubleValue() > rv.longValue(); break;
	 case ASTCondition.GE : result = lv.doubleValue() >= rv.longValue();break;
	 case ASTCondition.LT : result = lv.doubleValue() < rv.longValue(); break;
	 case ASTCondition.LE : result = lv.doubleValue() <= rv.longValue();break;
	 case ASTCondition.EQ : result = lv.doubleValue() == rv.longValue();break;
	 case ASTCondition.NEQ: result = lv.doubleValue() != rv.longValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Double lv, Float rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.doubleValue() > rv.floatValue(); break;
	 case ASTCondition.GE : result = lv.doubleValue() >= rv.floatValue();break;
	 case ASTCondition.LT : result = lv.doubleValue() < rv.floatValue(); break;
	 case ASTCondition.LE : result = lv.doubleValue() <= rv.floatValue();break;
	 case ASTCondition.EQ : result = lv.doubleValue() == rv.floatValue();break;
	 case ASTCondition.NEQ: result = lv.doubleValue() != rv.floatValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Double lv, Double rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.doubleValue() > rv.doubleValue(); break;
	 case ASTCondition.GE : result = lv.doubleValue() >= rv.doubleValue();break;
	 case ASTCondition.LT : result = lv.doubleValue() < rv.doubleValue(); break;
	 case ASTCondition.LE : result = lv.doubleValue() <= rv.doubleValue();break;
	 case ASTCondition.EQ : result = lv.doubleValue() == rv.doubleValue();break;
	 case ASTCondition.NEQ: result = lv.doubleValue() != rv.doubleValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Double lv, Character rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.doubleValue() > rv.charValue(); break;
	 case ASTCondition.GE : result = lv.doubleValue() >= rv.charValue();break;
	 case ASTCondition.LT : result = lv.doubleValue() < rv.charValue(); break;
	 case ASTCondition.LE : result = lv.doubleValue() <= rv.charValue();break;
	 case ASTCondition.EQ : result = lv.doubleValue() == rv.charValue();break;
	 case ASTCondition.NEQ: result = lv.doubleValue() != rv.charValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }

 /* Character vs other type */
static boolean evalRelAux(Character lv, Integer rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.charValue() > rv.intValue(); break;
	 case ASTCondition.GE : result = lv.charValue() >= rv.intValue(); break;
	 case ASTCondition.LT : result = lv.charValue() < rv.intValue(); break;
	 case ASTCondition.LE : result = lv.charValue() <= rv.intValue(); break;
	 case ASTCondition.EQ : result = lv.charValue() == rv.intValue(); break;
	 case ASTCondition.NEQ : result = lv.charValue() != rv.intValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Character lv, Long rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.charValue() > rv.longValue(); break;
	 case ASTCondition.GE : result = lv.charValue() >= rv.longValue();break;
	 case ASTCondition.LT : result = lv.charValue() < rv.longValue(); break;
	 case ASTCondition.LE : result = lv.charValue() <= rv.longValue();break;
	 case ASTCondition.EQ : result = lv.charValue() == rv.longValue();break;
	 case ASTCondition.NEQ: result = lv.charValue() != rv.longValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Character lv, Float rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.charValue() > rv.floatValue(); break;
	 case ASTCondition.GE : result = lv.charValue() >= rv.floatValue();break;
	 case ASTCondition.LT : result = lv.charValue() < rv.floatValue(); break;
	 case ASTCondition.LE : result = lv.charValue() <= rv.floatValue();break;
	 case ASTCondition.EQ : result = lv.charValue() == rv.floatValue();break;
	 case ASTCondition.NEQ: result = lv.charValue() != rv.floatValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Character lv, Double rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.charValue() > rv.doubleValue(); break;
	 case ASTCondition.GE : result = lv.charValue() >= rv.doubleValue();break;
	 case ASTCondition.LT : result = lv.charValue() < rv.doubleValue(); break;
	 case ASTCondition.LE : result = lv.charValue() <= rv.doubleValue();break;
	 case ASTCondition.EQ : result = lv.charValue() == rv.doubleValue();break;
	 case ASTCondition.NEQ: result = lv.charValue() != rv.doubleValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }
 static boolean evalRelAux(Character lv, Character rv, int op) {
     boolean result = false;
     switch(op) {
	 case ASTCondition.GT : result = lv.charValue() > rv.charValue(); break;
	 case ASTCondition.GE : result = lv.charValue() >= rv.charValue();break;
	 case ASTCondition.LT : result = lv.charValue() < rv.charValue(); break;
	 case ASTCondition.LE : result = lv.charValue() <= rv.charValue();break;
	 case ASTCondition.EQ : result = lv.charValue() == rv.charValue();break;
	 case ASTCondition.NEQ: result = lv.charValue() != rv.charValue();break;
	 default: System.err.println("Incorrect operator type : " + op );
		  break;
     }
     return result;
 }


 /**
  * This method evaluates relation between two Objects which are one of
  * Integer, Long, Float, Double and Character with given <code> op </code>
  * which indicates what relational function is applied.  What this method
  * actually does is to recognize types of two arguments and calls 
  * <code>evalRelAux</code> with passing these two arguments.
  */
 static boolean evalRelation(Object lv, Object rv, int op) {
     boolean result=false;
     if( lv instanceof Integer) { 	// Integer vs other type 
	 if( rv instanceof Integer) { 
	     result = ASTConditionAux.evalRelAux((Integer)lv,(Integer)rv,op);
	 } else if( rv instanceof Long) {
	     result = ASTConditionAux.evalRelAux((Integer)lv,(Long)rv,op);
	 } else if( rv instanceof Float) {
	     result = ASTConditionAux.evalRelAux((Integer)lv,(Float)rv,op);
	 } else if( rv instanceof Double) {
	     result = ASTConditionAux.evalRelAux((Integer)lv,(Double)rv,op);
	 } else if( rv instanceof Character) {
	     result = ASTConditionAux.evalRelAux((Integer)lv,(Character)rv,op);
	 } else { System.err.println("evalRelation has unexpected operands");
	 }
     } else if( lv instanceof Long) {	// Long vs other type
	 if( rv instanceof Integer) { 
	     result = ASTConditionAux.evalRelAux((Long)lv,(Integer)rv,op);
	 } else if( rv instanceof Long) {
	     result = ASTConditionAux.evalRelAux((Long)lv,(Long)rv,op);
	 } else if( rv instanceof Float) {
	     result = ASTConditionAux.evalRelAux((Long)lv,(Float)rv,op);
	 } else if( rv instanceof Double) {
	     result = ASTConditionAux.evalRelAux((Long)lv,(Double)rv,op);
	 } else if( rv instanceof Character) {
	     result = ASTConditionAux.evalRelAux((Long)lv,(Character)rv,op);
	 } else { System.err.println("evalRelation has unexpected operands");
	 }
     } else if( lv instanceof Float) {	// Float vs other type
	 if( rv instanceof Integer) { 
	     result = ASTConditionAux.evalRelAux((Float)lv,(Integer)rv,op);
	 } else if( rv instanceof Long) {
	     result = ASTConditionAux.evalRelAux((Float)lv,(Long)rv,op);
	 } else if( rv instanceof Float) {
	     result = ASTConditionAux.evalRelAux((Float)lv,(Float)rv,op);
	 } else if( rv instanceof Double) {
	     result = ASTConditionAux.evalRelAux((Float)lv,(Double)rv,op);
	 } else if( rv instanceof Character) {
	     result = ASTConditionAux.evalRelAux((Float)lv,(Character)rv,op);
	 } else { System.err.println("evalRelation has unexpected operands");
	 }
     } else if( lv instanceof Double) {	// Double vs other type
	 if( rv instanceof Integer) { 
	     result = ASTConditionAux.evalRelAux((Double)lv,(Integer)rv,op);
	 } else if( rv instanceof Long) {
	     result = ASTConditionAux.evalRelAux((Double)lv,(Long)rv,op);
	 } else if( rv instanceof Float) {
	     result = ASTConditionAux.evalRelAux((Double)lv,(Float)rv,op);
	 } else if( rv instanceof Double) {
	     result = ASTConditionAux.evalRelAux((Double)lv,(Double)rv,op);
	 } else if( rv instanceof Character) {
	     result = ASTConditionAux.evalRelAux((Double)lv,(Character)rv,op);
	 } else { System.err.println("evalRelation has unexpected operands");
	 }
     } else if( lv instanceof Character) {// Character vs other type
	 if( rv instanceof Integer) { 
	     result = ASTConditionAux.evalRelAux((Character)lv,(Integer)rv,op);
	 } else if( rv instanceof Long) {
	     result = ASTConditionAux.evalRelAux((Character)lv,(Long)rv,op);
	 } else if( rv instanceof Float) {
	     result = ASTConditionAux.evalRelAux((Character)lv,(Float)rv,op);
	 } else if( rv instanceof Double) {
	     result = ASTConditionAux.evalRelAux((Character)lv,(Double)rv,op);
	 } else if( rv instanceof Character) {
	     result = ASTConditionAux.evalRelAux((Character)lv,(Character)rv,op);
	 } else { System.err.println("evalRelation has unexpected operands");
	 }
     } else { System.err.println("evalRelation has unexpected operands");
     }
     return result;
 }
}
